package com.ningkang.auth.controller;

import com.ningkang.auth.domain.LoginParam;
import com.ningkang.auth.domain.LoginResponse;
import com.ningkang.auth.service.AuthService;
import com.ningkang.common.domain.ums.UserVo;
import com.ningkang.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName：AuthController
 * @Author: LeiHao
 * @Date: 2024/10/17 17:08
 * @Description: 认证中心控制层
 */

@RestController
@RequestMapping("auth")
@Validated
public class AuthController {
    @Autowired
    private AuthService authService;
    /* *
     * @Title: login
     * @Author: DELL
     * @Date: 2024-10-17 17:19:58
     * @Params: [loginParam]
     * @Return: Result<LoginResponse>
     * @Description: 用户名密码登录
     */
    @PostMapping("login")
    public Result<LoginResponse> login(@Valid @RequestBody LoginParam loginParam){
        LoginResponse loginResponse = authService.login(loginParam);
        return Result.success(loginResponse);
    }

    /* *
     * @Title: getUserInfo
     * @Author: DELL
     * @Date: 2024-10-18 10:30:29
     * @Params: []
     * @Return: Result<UserVo>
     * @Description: 获取登录信息
     */
    @GetMapping("getUserInfo")
    public Result<UserVo> getUserInfo(){
        UserVo userVo = authService.getUserInfo();
        return Result.success(userVo);
    }

    /* *
     * @Title: logout
     * @Author: DELL
     * @Date: 2024-10-18 10:31:00
     * @Params: []
     * @Return: Result
     * @Description: 登出功能
     */
    @PostMapping("logout")
    public Result logout(){
        authService.logout();
        return Result.success("退出成功");
    }
}

